<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <!-- 视图定义 router-view组件 路由组件的出口 匹配路由组件就会在router-view位置处渲染 -->
    <router-view></router-view>
  </div>
  <script src="./vue.js"></script>
  <script src="./vue-router.js"></script>

  <script>
    // 先准备  三个 路由组件  config
    const Home = {
      template: `
        <div>
          <h2>这是首页</h2>  
        </div>
      `
    }
    const News = {
      template: `
        <div>
          <h2>这是新闻页</h2>  
        </div>
      `
    }
    const About = {
      template: `
        <div>
          <h2>这是关于我们页</h2>  
        </div>
      `
    }
    const routes = [
      {
        path: '/', // 路由path
        component: Home
      },
      {
        path: '/news',
        component: News
      },
      {
        path: '/about',
        component: About
      }
    ]
    // 定义路由实例对象并 注册 路由规则
    const router = new VueRouter({
      // routes 路由规则
      routes
    });
    // 将路由实例 挂载到vm上
    const vm = new Vue({
      el: '#app',
      router
    })
  </script>
</body>
</html>